/*
 * @Author: dark-snow 1306808708@qq.com
 * @Date: 2023-07-04 16:57:10
 * @LastEditors: dark-snow 1306808708@qq.com
 * @LastEditTime: 2023-07-04 17:01:20
 * @FilePath: \wifi_server_030704\components\user_component\include\user_socket.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */


#ifndef _USER_SOCKET_H_
#define _USER_SOCKET_H_

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_mac.h"
#include "esp_system.h"
#include "esp_log.h"

#include "lwip/err.h"
#include "lwip/sys.h"
#include "sys/socket.h"
// #include "esp_wifi.h"

// #include "user_dict.h"

#define TCP_SERVER 1
#define TCP_CLIENT 0

#define TCP_PROTOCOL_TYPE TCP_SERVER

// 临时，后面可以改成字典
typedef struct client_para
{
	int sock;
	struct sockaddr_in addr;
	uint addrLen;
} Client_Info;

void tcp_server_init_task(void *pt);
void tcp_server_accpt_mult_task(void *pt);
void recv_clientSock_info_task(Client_Info *client_info);
void tcp_server_close(void *pt);
void tcp_client_close(int sock);
void tcp_send(int sock, char *tx_buf);

/******************        client list                 ******************/
#define SOCK_MAX_NUM (MAX_CLIENT_CONNECT_NUM + 1)
extern Client_Info client_list[];

void client_list_add(Client_Info data);
void client_list_remove(int sock);
void client_list_remove_all(void);
/******************        client dict                 ******************/

/**
#define client_dict_read_sock(node) (*((int *)node->key))

Client_Info *client_dict_read_data(dict *head, int key);
void client_dict_init_head(dict *head, int *key, Client_Info *data);
void client_dict_insert_node(dict *head, int *key, Client_Info *data);
void client_dict_delete_node(dict *head, int num);
void client_dict_clear_node(dict *head);
**/
#endif